home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Programming Contest / ~Solutions Submitted / Problem 02 - Three and One / Solution.p < prev   
Encoding:
Text File  |  1998-06-19  |  1.6 KB  |  61 lines  |  [TEXT/CWIE]

  1. (*
  2. Problem 02 - Hower of Tanoi
  3.  
  4. This problem is to solve a variant of the Tower of Hanoi puzzle.  You remember
  5. the Tower of Hanoi, a board with three pegs, one of which has N disks of size
  6. 1, 2, 3, ... N, with the smallest disk at the top.  In the standard puzzle, the
  7. goal is to move all of the disks from one peg to another peg, by repeatedly
  8. moving a disk from the top of one peg to another peg without ever placing a
  9. larger disk on top of a smaller disk.
  10.  
  11. In our Hower of Tanoi problem, the objective and the constraints are the same,
  12. except that the disks on the first peg are initially in random order. You can
  13. still only move a smaller disk onto a larger disk.
  14.  
  15. Your objective is output the moves required to place all the disks on peg 3 in
  16. order with the smallest disk at the top.  
  17.  
  18. Input specification
  19.  
  20. The first line of the input file contains an integer M, M<1000, the number of
  21. disks in the problem.  The next M lines contain the numbers 1 .. M, one number
  22. per line, randomly ordered, where the first number is the size of the top disk
  23. on peg 1, the second number is the size of the 2nd disk from the top, etc.
  24.  
  25. Output specification
  26.  
  27. The output is a sequence of lines, each representing a single move,  consisting
  28. of the source peg number followed by a comma (',') followed by the destination
  29. peg number, followed by a return character.
  30.  
  31. Sample input
  32.  
  33. 2
  34. 2
  35. 1
  36.  
  37. Sample output
  38.  
  39. 1,3
  40. 1,3
  41. *)
  42.  
  43. unit Solution;
  44.  
  45. interface
  46.  
  47. // Do not modify the interface
  48.  
  49.     uses
  50.         Types, Files;
  51.         
  52.     function HowerOfTanoi( const infile, outfile: FSSpec ): OSErr;
  53.  
  54. implementation
  55.  
  56. // Fill in your solution and then submit this folder
  57.  
  58. // Team Name: FILL IN YOUR TEAM NAME!
  59.  
  60. end.
  61.